import Vue from 'vue'
import Vuex from 'vuex'
import axios from '@/axios'
import { routers } from '@/router'


Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
        token: '',
        user:'',
        routers,
    },
    mutations: {
        cuntoken(state, token) {
            state.token = token  // state中存token
        },
        cxtoken(state,profile) { 
            state.user=profile
        },
        removetoken(state) {    
            state.token=''
        }
    },
    actions: {
        chatoken({ commit }, token) { 
            return new Promise((resolve,reject) => { 
                axios.get('/userinfo/', {
                    headers: {
                        token
                    }
                }).then((res) => { 
                    resolve(res.data)
                })
            })
        }
    }
})
export default store